package com.example.userservice.novel.controller;

import com.example.userservice.novel.entity.NovelGenerateRequest;
import com.example.userservice.novel.entity.NovelGenerateResponse;
import com.example.userservice.novel.entity.NovelStructure;
import com.example.userservice.novel.service.EnhancedNovelService;
import com.example.userservice.novel.service.SimpleNovelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/novelNew")
//@Slf4j
public class NewNovelController {

    @Autowired
    private EnhancedNovelService enhancedNovelService;

    /**
     * 生成小说架构并保存 - 基础版本
     */
    @PostMapping("/generate")
    public ResponseEntity<NovelGenerateResponse> generateNovel(
            @RequestBody NovelGenerateRequest request) {

//        log.info("开始生成并保存小说架构: {}", request.getNovelName());
        System.out.println("开始生成并保存小说架构:" + request.getNovelName());
        NovelGenerateResponse response = enhancedNovelService.generateAndSaveNovel(request);

        if (response.isSuccess()) {
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
        }
    }

    /**
     * 分步骤生成小说架构并保存
     */
    @PostMapping("/generate-step")
    public ResponseEntity<NovelGenerateResponse> generateNovelStepByStep(
            @RequestBody NovelGenerateRequest request) {

//        log.info("开始分步骤生成并保存小说架构: {}", request.getNovelName());
        System.out.println("开始分步骤生成并保存小说架构:" + request.getNovelName());
        NovelGenerateResponse response = enhancedNovelService.generateStepByStepAndSave(request);

        if (response.isSuccess()) {
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
        }
    }

    /**
     * 快速生成接口（GET方式）
     */
    @GetMapping("/quick-generate")
    public ResponseEntity<NovelGenerateResponse> quickGenerate(
            @RequestParam String novelName) {

        NovelGenerateRequest request = new NovelGenerateRequest(novelName);
        return generateNovel(request);
    }

    /**
     * 健康检查
     */
    @GetMapping("/health")
    public String healthCheck() {
        return "OK";
    }

}
